<template>
  <div class="image-list">
    <el-image
      v-for="image in fileList"
      :key="image.name"
      :src="getPreviewUrl(image.name)"
      style="width: 54px; height: 54px; border-radius: 4px; margin-right: 8px"
      preview-teleported
      :preview-src-list="fileUrls"
      loading="lazy"
      lazy
    ></el-image>
  </div>
</template>

<script lang="ts" setup name="imageListRow">
import { getPreviewUrl } from '/@/utils';
import { computed } from 'vue';

const props = defineProps({
  files: {
    default: []
  }
});

const fileList = computed(() => {
  if (typeof props.files === 'string') {
    return JSON.parse(props.files);
  }
  return props.files;
});

const fileUrls = computed(() => {
  return fileList.value.map((item: any) => {
    return getPreviewUrl(item.name);
  });
});
</script>
